graph = {
    'A': ['B', 'C'],
    'B': ['D'],
    'C': ['E'],
    'D': [],
    'E': []
}

# BFS遍历
from collections import deque
def bfs(graph, start):
    visited = set()
    q = deque([start])
    while q:
        node = q.popleft()
        if node not in visited:
            print(node)
            visited.add(node)
            q.extend(graph[node])

bfs(graph, 'A')